<?php
App::uses('AdminbaseController', 'Controller'); 
class AdminajaxController extends AdminbaseController {  

    function beforeFilter() { 
        parent::beforeFilter();  
    }
  
    //切换状态
    function toggle()
    { 
        $params = $this->request->query;
        $act = $params['ajaxdata']; 
        $this->checkLogin(1);  
        $c_id = $params['id']?intval($params['id']):0; 
        $c_val = $params['val']?$params['val']:0;  
        if($c_id<=0)
        {
            $this->ajaxReturn(4001, '参数异常！'); 
        }
        $data=[];
        $data['id']=$c_id;  
        $data['status']=$c_val;  
        switch ($act) { 
            case 'account':   
                $this->admin_power('users_account_edit',1);
                $this->loadModel('User');  
                $dataList = $this->User->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '用户不存在！'); 
                if(!$this->User->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "用户状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'appoint':   
                $this->admin_power('users_appoint_list',1);
                $this->loadModel('UsersAppoint'); 
                $dataList = $this->UsersAppoint->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '预约不存在！'); 
                if(!$this->UsersAppoint->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "预约状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;    
            case 'manages':  
                $this->admin_power('adminmanage_edit',1); 
                $this->loadModel('AdminUser');  
                $dataList = $this->AdminUser->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '管理员不存在！'); 
                if(!$this->AdminUser->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "管理员状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'mapcate':  
                $this->admin_power('map_cates_edit',1); 
                $this->loadModel('MapCate');  
                $dataList = $this->MapCate->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '分类不存在！'); 
                if(!$this->MapCate->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "地图分类状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'map':  
                $this->admin_power('map_cates_edit',1); 
                $this->loadModel('Map');  
                $dataList = $this->Map->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '地图不存在！'); 
                if(!$this->Map->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "地图状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'link':   
                $this->admin_power('link_edit',1);
                $this->loadModel('Link');  
                $dataList = $this->Link->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '友情链接不存在！'); 
                if(!$this->Link->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "情链接状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'cate':   
                $this->admin_power('article_cate_edit',1);
                $this->loadModel('ArticleCate');  
                $dataList = $this->ArticleCate->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '分类不存在！'); 
                if(!$this->ArticleCate->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "攻略分类状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'news':   
                $this->admin_power('news_edit',1);
                $this->loadModel('New');
                $dataList = $this->New->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '新闻不存在！'); 
                if(!$this->New->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "新闻状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'news_home':   
                $this->admin_power('news_edit',1);
                $this->loadModel('New');
                $dataList = $this->New->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '新闻不存在！'); 
                unset($data['status']);
                $data['is_home']=$c_val;  
                if(!$this->New->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "新闻状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'article':   
                $this->admin_power('article_edit',1);
                $this->loadModel('Article');  
                $dataList = $this->Article->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '攻略不存在！'); 
                if(!$this->Article->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "攻略状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'article_top':   
                $this->admin_power('article_edit',1);
                $this->loadModel('Article');  
                $dataList = $this->Article->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '攻略不存在！');  
                unset($data['status']);
                $data['is_top']=$c_val;  
                if(!$this->Article->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "攻略推荐状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;  
            case 'ask':   
                $this->admin_power('users_ask_edit',1);
                $this->loadModel('Share');    
                $dataList = $this->Share->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '提问不存在！'); 
                if(!$this->Share->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "提问状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'ask_top':   
                $this->admin_power('users_ask_edit',1);
                $this->loadModel('Share');    
                $dataList = $this->Share->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '提问不存在！'); 
                unset($data['status']);
                $data['is_top']=$c_val;  
                if(!$this->Share->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "提问置顶状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'share':   
                $this->admin_power('share_edit',1);
                $this->loadModel('Share');    
                $dataList = $this->Share->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '分享不存在！'); 
                if(!$this->Share->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "分享状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'share_top':   
                $this->admin_power('share_edit',1);
                $this->loadModel('Share');  
                $dataList = $this->Share->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '分享不存在！');  
                unset($data['status']);
                $data['is_top']=$c_val;  
                if(!$this->Share->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "分享置顶状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'article_elite':   
                $this->admin_power('article_edit',1);
                $this->loadModel('Article');  
                $dataList = $this->Article->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '攻略不存在！'); 
                unset($data['status']);
                $data['is_elite']=$c_val;  
                if(!$this->Article->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "攻略精华状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'video_cate':   
                $this->admin_power('video_cate_edit',1);
                $this->loadModel('VideoCate');  
                $dataList = $this->VideoCate->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '分类不存在！'); 
                if(!$this->VideoCate->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "视频分类状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'video_cate_top':   
                $this->admin_power('video_cate_edit',1);
                $this->loadModel('VideoCate');  
                $dataList = $this->VideoCate->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '分类不存在！'); 
                unset($data['status']);
                $data['is_top']=$c_val;  
                if(!$this->VideoCate->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "视频分类置顶状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'comment':   
                $this->admin_power('users_comment_edit',1);
                $this->loadModel('Comment');
                $dataList = $this->Comment->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '评论不存在！'); 
                unset($data['status']);
                $data['is_top']=$c_val;  
                if(!$this->Comment->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "评论置顶状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'video':   
                $this->admin_power('video_edit',1);
                $this->loadModel('Video');  
                $dataList = $this->Video->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '视频不存在！'); 
                if(!$this->Video->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "视频状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'video_rec':   
                $this->admin_power('video_edit',1);
                $this->loadModel('Video');  
                $dataList = $this->Video->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '视频不存在！'); 
                unset($data['status']);
                $data['rec']=$c_val;  
                if(!$this->Video->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "视频推荐状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'music':   
                $this->admin_power('music_edit',1);
                $this->loadModel('Audio');  
                $dataList = $this->Audio->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '音频不存在！'); 
                if(!$this->Audio->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "音频状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'albums':   
                $this->admin_power('music_albums_edit',1);
                $this->loadModel('Album');  
                $dataList = $this->Album->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '专辑不存在！'); 
                if(!$this->Album->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "专辑状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break; 
            case 'hospital':   
                $this->admin_power('hospital_edit',1);
                $this->loadModel('Hospital');  
                $dataList = $this->Hospital->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '医院不存在！'); 
                if(!$this->Hospital->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "医院状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'doctor':   
                $this->admin_power('doctor_edit',1);
                $this->loadModel('Doctor');  
                $dataList = $this->Doctor->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '医生不存在！'); 
                if(!$this->Doctor->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "医生状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;
            case 'doctor_rec':   
                $this->admin_power('doctor_edit',1);
                $this->loadModel('Doctor');  
                $dataList = $this->Doctor->findById($c_id);  
                if(empty($dataList))
                    $this->ajaxReturn(4002, '医生不存在！'); 
                unset($data['status']);
                $data['rec']=$c_val;  
                if(!$this->Doctor->save($data)){ 
                    $this->ajaxReturn(4003, '变更失败！'); 
                }
                $this->adminLog($c_id, 'edit', "医生推荐状态",$data);
                $this->ajaxReturn(200, '变更成功！',array('res' => $c_val)); 
                break;  
            default:
                break;
        }
        die();
    }  

    public function del(){ 
        $params = $this->request->query;
        $act = $params['ajaxdata']; 
        $rid = $params['rid']?intval($params['rid']):0; 
        $deltype = $params['type']?$params['type']:'single';  
        $this->checkLogin(1);  
        if(empty($act) || $rid<=0)
        {
            $this->ajaxReturn(4001, '参数异常！'); 
        }   
        switch ($act) {  
            case 'roles': 
                $this->admin_power('adminmanage_roles_edit',1);
                $this->loadModel('AdminGroup');  
                if($deltype=='single'){ 
                    //处理角色删除
                    $this->data_delete('AdminGroup',array('id' => $rid)); 
                    //角色资源删除    
                    $this->loadModel('AdminPermission');  
                    $this->AdminPermission->deleteAll(array('gid'=>$rid));  
                    $this->adminLog($rid, 'del', "角色");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'manages':  
                $this->admin_power('adminmanage_edit_boss',1); 
                $this->loadModel('AdminUser');  
                if($deltype=='single'){ 
                    //处理角色删除
                    $this->data_delete('AdminUser',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "管理员");
                } 
                $this->ajaxReturn(200, '已删除！');  
                break;
            case 'keywords': 
                $this->admin_power('keywords_edit',1);
                $this->loadModel('Keyword');  
                if($deltype=='single'){ 
                    //处理角色删除
                    $this->data_delete('Keyword',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "keywords");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break;
            case 'specials': 
                $this->admin_power('specials_edit',1);
                $this->loadModel('Special');  
                if($deltype=='single'){ 
                    //处理角色删除
                    $this->data_delete('Special',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "自定义专题");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break;
            case 'account': 
                $this->admin_power('users_account_list',1);
                $this->loadModel('User');  
                $this->loadModel('Share');  
                $this->loadModel('Article');  
                $this->loadModel('Comment');  
                if($deltype=='single'){ 
                    $this->data_delete('User',array('id' => $rid));   
                    //删除对应攻略，分享，问答，评论
                    $this->Share->deleteAll(['uid =' => $rid]);
                    $this->Article->deleteAll(['uid =' => $rid]);
                    $this->Comment->deleteAll(['uid =' => $rid]); 
                    $this->adminLog($rid, 'del', "会员");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break;
            case 'site': 
                $this->admin_power('site_comments_edit',1);
                $this->loadModel('SiteComment');  
                if($deltype=='single'){ 
                    //处理角色删除
                    $this->data_delete('SiteComment',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "赴泰点评");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break;  
            case 'joins': 
                $this->admin_power('join_edit',1);
                $this->loadModel('Join');  
                if($deltype=='single'){ 
                    //处理角色删除
                    $this->data_delete('Join',array('id' => $rid));   
                    $this->adminLog($rid, 'del', "招聘");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'map': 
                $this->admin_power('map_edit',1); 
                $this->loadModel('Map');  
                if($deltype=='single'){  
                    $this->data_delete('Map',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "地图");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'channel':   
                $this->admin_power('channel_edit',1);
                $this->loadModel('Yonghuqudao');  
                if($deltype=='single'){  
                    $this->data_delete('Yonghuqudao',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "渠道");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'link': 
                $this->admin_power('link_edit',1); 
                $this->loadModel('Link');  
                if($deltype=='single'){  
                    $this->data_delete('Link',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "友情链接");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'video': 
                $this->admin_power('video_edit',1); 
                $this->loadModel('Video');  
                if($deltype=='single'){  
                    $this->data_delete('Video',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "视频");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'news': 
                $this->admin_power('news_edit',1); 
                $this->loadModel('New');
                if($deltype=='single'){  
                    $this->data_delete('New',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "新闻");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break;
            case 'article': 
                $this->admin_power('article_edit',1); 
                $this->loadModel('Article');
                if($deltype=='single'){  
                    $this->data_delete('Article',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "攻略");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'music': 
                $this->admin_power('music_edit',1); 
                $this->loadModel('Audio');    
                if($deltype=='single'){  
                    $this->data_delete('Audio',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "音频");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'comment': 
                $this->admin_power('users_comment_edit',1); 
                $this->loadModel('Comment');    
                if($deltype=='single'){  
                    $this->data_delete('Comment',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "评论");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'comment': 
                $this->admin_power('users_comment_edit',1); 
                $this->loadModel('Comment');    
                if($deltype=='single'){  
                    $this->data_delete('Comment',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "评论");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'album': 
                $this->admin_power('music_albums_edit',1); 
                $this->loadModel('Album');    
                if($deltype=='single'){  
                    $this->data_delete('Album',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "音频专辑");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break;
            case 'hospital': 
                $this->admin_power('hospital_del',1); 
                $this->loadModel('Hospital');    
                if($deltype=='single'){  
                    $this->data_delete('Hospital',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "医院");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break;
            case 'doctor': 
                $this->admin_power('doctor_del',1); 
                $this->loadModel('Doctor');    
                if($deltype=='single'){  
                    $this->data_delete('Doctor',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "医生");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'share': 
                $this->admin_power('share_del',1); 
                $this->loadModel('Share');    
                if($deltype=='single'){  
                    $this->data_delete('Share',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "分享");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            case 'answer': 
                $this->admin_power('answer_del',1); 
                $this->loadModel('Share');    
                if($deltype=='single'){  
                    $this->data_delete('Share',array('id' => $rid));  
                    $this->adminLog($rid, 'del', "问答");
                } 
                $this->ajaxReturn(200, '已删除！'); 
                break; 
            default:
                break;
        }
        die();
    }


    public function other(){  
        $params = $this->request->data;
        $act = $params['ajaxdata'];  
        $this->checkLogin(1);  
        if(empty($act))
        {
            $this->ajaxReturn(4001, '参数异常！'); 
        }   
        switch ($act) {  
            case 'cate':   
                $list = isset($params['val'])?json_decode($params['val']):[];  
                if(empty($list))
                {
                    $this->ajaxReturn(4001, '参数异常！'); 
                }  
                //检查权限
                $this->admin_power('article_cate_edit',1); 
                $this->loadModel('ArticleCate');  
                //改变结构及排序
                $sort=100; 
                foreach ($list as $key => $value) {
                    $data=array(); 
                    $data=['sort'=>$sort,'id'=>$value->id,'parent_id'=>0];    
                    $this->ArticleCate->save($data);
                    $sort++;
                    if(isset($value->children)){
                        foreach ($value->children as $kk => $vv) {
                            $data=['sort'=>$sort,'id'=>$vv->id,'parent_id'=>$value->id];  
                            $this->ArticleCate->save($data);
                            $sort++;
                        }
                    } 
                }
                $this->ajaxReturn(200, '变更成功！');  
                break;  
            case 'video_cate':   
                $list = isset($params['val'])?json_decode($params['val']):[];  
                if(empty($list))
                {
                    $this->ajaxReturn(4001, '参数异常！'); 
                }  
                //检查权限
                $this->admin_power('video_cate_edit',1); 
                $this->loadModel('VideoCate');  
                //改变结构及排序
                $sort=100; 
                foreach ($list as $key => $value) {
                    $data=array(); 
                    $data=['sort'=>$sort,'id'=>$value->id,'parent_id'=>0];    
                    $this->VideoCate->save($data);
                    $sort++;
                    if(isset($value->children)){
                        foreach ($value->children as $kk => $vv) {
                            $data=['sort'=>$sort,'id'=>$vv->id,'parent_id'=>$value->id];  
                            $this->VideoCate->save($data);
                            $sort++;
                        }
                    } 
                }
                $this->ajaxReturn(200, '变更成功！');  
                break;   
            default:
                break;
        }
        die();
    } 

    public function file() { 
        $params = $this->request->query;
        $act = $params['ajaxdata'];  
        $this->checkLogin(1);  
        $this->loadModel('Picture');  
        if(empty($act)) 
            $this->ajaxReturn(4001, '参数异常！');   
        switch ($act) {    
            case 'article':     
                $pictype=Configure::read('PIC_TOPIC');
                if (!empty($_FILES['file']['name'])) {   
                    // 上传文件 
                    $fName=explode(".", $_FILES['file']['name']);
                    $_FILES['imgFile']=$_FILES['file'];
                    $attrRes=Ivf::uploadImg('/uploads/article/');
                    if($attrRes['status']!=200)
                        $this->ajaxReturn(4002, '图片上传失败！原因:'.$attrRes['message']);   
                    //生成缩略图 
                    $php_path = dirname(dirname(dirname(__FILE__))).'/webroot';
                    //文件保存目录路径    
                    $thumb_path=$attrRes['save_url']."thumb/"; 
                    if(!file_exists($php_path.$thumb_path)){
                        mkdir($php_path.$thumb_path);
                    }
                    $new_image_path=$thumb_path.$attrRes['save_name'];  
                    Ivf::thumb_pic($php_path.$attrRes['url'],$php_path.$new_image_path);

                    $data=[];
                    $data['image'] =$attrRes['url'];   
                    $data['obj_type'] = $pictype['攻略'];  
                    $data['thumb'] =$new_image_path;  
                    $data['obj_id']=0;
                    $data['mimetype']=$fName[1];  
                    $this->Picture->save($data);
                     
                    $this->ajaxReturn(200, '上传成功！',array('id'=>$this->Picture->id,'url'=>$data['thumb']));  
                }  
                $this->ajaxReturn(4002, '上传失败！'); 
                break; 
            case 'hospit':     
                $pictype=Configure::read('PIC_TOPIC');
                if (!empty($_FILES['file']['name'])) {   
                    // 上传文件 
                    $fName=explode(".", $_FILES['file']['name']);
                    $_FILES['imgFile']=$_FILES['file'];
                    $attrRes=Ivf::uploadImg('/uploads/hospital/');
                    if($attrRes['status']!=200)
                        $this->ajaxReturn(4002, '图片上传失败！原因:'.$attrRes['message']);   
                    //生成缩略图 
                    $php_path = dirname(dirname(dirname(__FILE__))).'/webroot';
                    //文件保存目录路径    
                    $thumb_path=$attrRes['save_url']."thumb/"; 
                    if(!file_exists($php_path.$thumb_path)){
                        mkdir($php_path.$thumb_path);
                    }
                    $new_image_path=$thumb_path.$attrRes['save_name'];  
                    Ivf::thumb_pic($php_path.$attrRes['url'],$php_path.$new_image_path);

                    $data=[];
                    $data['image'] =$attrRes['url'];   
                    $data['obj_type'] = $pictype['医院'];  
                    $data['thumb'] =$new_image_path;  
                    $data['obj_id']=0;
                    $data['mimetype']=$fName[1];  
                    $this->Picture->save($data);
                     
                    $this->ajaxReturn(200, '上传成功！',array('id'=>$this->Picture->id,'url'=>$data['thumb']));  
                }  
                $this->ajaxReturn(4002, '上传失败！'); 
                break;
            case 'share':     
                $pictype=Configure::read('PIC_TOPIC');
                if (!empty($_FILES['file']['name'])) {   
                    // 上传文件 
                    $fName=explode(".", $_FILES['file']['name']);
                    $_FILES['imgFile']=$_FILES['file'];
                    $attrRes=Ivf::uploadImg('/uploads/share/');
                    if($attrRes['status']!=200)
                        $this->ajaxReturn(4002, '图片上传失败！原因:'.$attrRes['message']);   
                    //生成缩略图 
                    $php_path = dirname(dirname(dirname(__FILE__))).'/webroot';
                    //文件保存目录路径    
                    $thumb_path=$attrRes['save_url']."thumb/"; 
                    if(!file_exists($php_path.$thumb_path)){
                        mkdir($php_path.$thumb_path);
                    }
                    $new_image_path=$thumb_path.$attrRes['save_name'];  
                    Ivf::thumb_pic($php_path.$attrRes['url'],$php_path.$new_image_path);

                    $data=[];
                    $data['image'] =$attrRes['url'];   
                    $data['obj_type'] = $pictype['分享'];  
                    $data['thumb'] =$new_image_path;  
                    $data['obj_id']=0;
                    $data['mimetype']=$fName[1];  
                    $this->Picture->save($data);
                     
                    $this->ajaxReturn(200, '上传成功！',array('id'=>$this->Picture->id,'url'=>$data['thumb']));  
                }  
                $this->ajaxReturn(4002, '上传失败！'); 
                break;
            case 'answer':     
                $pictype=Configure::read('PIC_TOPIC');
                if (!empty($_FILES['file']['name'])) {   
                    // 上传文件 
                    $fName=explode(".", $_FILES['file']['name']);
                    $_FILES['imgFile']=$_FILES['file'];
                    $attrRes=Ivf::uploadImg('/uploads/answer/');
                    if($attrRes['status']!=200)
                        $this->ajaxReturn(4002, '图片上传失败！原因:'.$attrRes['message']);   
                    //生成缩略图 
                    $php_path = dirname(dirname(dirname(__FILE__))).'/webroot';
                    //文件保存目录路径    
                    $thumb_path=$attrRes['save_url']."thumb/"; 
                    if(!file_exists($php_path.$thumb_path)){
                        mkdir($php_path.$thumb_path);
                    }
                    $new_image_path=$thumb_path.$attrRes['save_name'];  
                    Ivf::thumb_pic($php_path.$attrRes['url'],$php_path.$new_image_path);

                    $data=[];
                    $data['image'] =$attrRes['url'];   
                    $data['obj_type'] = $pictype['问答'];  
                    $data['thumb'] =$new_image_path;  
                    $data['obj_id']=0;
                    $data['mimetype']=$fName[1];  
                    $this->Picture->save($data);
                     
                    $this->ajaxReturn(200, '上传成功！',array('id'=>$this->Picture->id,'url'=>$data['thumb']));  
                }  
                $this->ajaxReturn(4002, '上传失败！'); 
                break; 
            case 'del_pic': 
                $rid = $params['val']?intval($params['val']):0;  
                if(intval($rid) <= 0) 
                    $this->ajaxReturn(4002, '参数异常！');   
 
                $this->data_delete('Picture',array('id' => $rid));   
                $this->ajaxReturn(200, '已删除！');  
                break; 
            default:
                break;
        }
        die();
    }

}